<?php

namespace App\Services\Message;

use App\Models\Msg\TplModel;

/**
 * 消息模板
 *
 * @example
 * @author mengsen
 * @since
 */

class MsgTplService
{
    public static function format($param = [])
    {
        if (empty($param['tpl_id'])) {
            throw new \Exception("模板ID不可为空");
        }

        $tpl = TplModel::getInfo(['tpl_id' => $param['tpl_id']], 'rules,template,plat');
        switch ($tpl['plat']) {
            case 1:
                break;
            case 2:
                $search = [];
                $replace = [];
                foreach ($param as $k => $v) {
                    $search[] = '{' . $k . '}';
                    $replace[] = $v;
                }
                $tpl['template'] = str_replace($search, $replace, $tpl['template']);
                break;
        }
        return $tpl;
    }
}
